import os
import re
import time
import sys
from threading import Thread
import urllib

class testit(Thread):
    def __init__ (self,ip):
        Thread.__init__(self)
        self.ip = ip
        self.status = -1
    def run(self):
        pingaling = os.popen("ping -q -c2 "+self.ip,"r")
        while 1:
            line = pingaling.readline()
            if not line: break
            igot = re.findall(testit.lifeline,line)
            if igot:
                self.status = int(igot[0])

def main():
    testit.lifeline = re.compile(r"(\d) received")
    report = ("No response","Partial Response","Alive")

    print time.ctime()

    pinglist = []

    for host in range(60,70):
        ip = "192.168.200."+str(host)
        current = testit(ip)
        pinglist.append(current)
        current.start()

    for pingle in pinglist:
        pingle.join()
        print "Status from ",pingle.ip,"is",report[pingle.status]

    print time.ctime()

if __name__ == '__main__':
    time_main = time.time()
    for i in range(3):
        urllib.urlopen('http://tera.thaigrid.or.th/~chakkrit_ta/webgraph/api.py?value=source&maximum=10000&service=list')
        print i
    print 'Average',(time.time()-time_main)/10

